<template>
  <div>
    <div class="publicSearch">
      <div class="searchBar">
        <el-button-group>
          <el-button @click="getCompanyData" size="mini" icon="el-icon-search"
            >查询</el-button
          >
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh"
            >重置</el-button
          >
        </el-button-group>
        <div>
          <span>关键字搜索</span>
          <el-input
            v-model="searchData.keyWords"
            size="mini"
            placeholder="公司名称"
            clearable
          ></el-input>
        </div>
      </div>

      <div class="tableBox">
        <el-table highlight-current-row :data="companies" style="width: 100%">
          <el-table-column type="index" width="50"> </el-table-column>
          <el-table-column
            sortable
            show-overflow-tooltip
            prop="name"
            label="公司名称"
            width="180"
          >
          </el-table-column>
          <el-table-column
            sortable
            show-overflow-tooltip
            prop="companyAddress"
            label="详细地址"
            width="300"
          >
          </el-table-column>
          <el-table-column
            sortable
            show-overflow-tooltip
            prop="createTime"
            label="创建时间"
            width="300"
          >
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="110">
            <template slot-scope="scope">
              <el-button
                @click="pass(scope.row.id)"
                icon="iconfont icon-dui"
                type="primary"
                circle
                plain
                size="small"
              ></el-button>
              <el-button
                @click="refuse(scope.row.id)"
                icon="iconfont icon-icon1"
                type="primary"
                circle
                plain
                size="small"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          class="pagination-bottom"
          style="text-align: right"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :page-sizes="[15, 30, 50, 100]"
          :current-page.sync="searchData.pageNum"
          :page-size="searchData.pageSize"
          layout="sizes, total, prev, pager, next, jumper"
          :total="searchData.total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CompanyNew",
  data() {
    return {
      searchData: {
        pageNum: 1,
        pageSize: 15,
        total: null,
        keyWords: "",
      },
      companies: [],
    };
  },
  created() {
    this.getCompanyData();
  },
  watch: {},
  methods: {
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getPlatformData();
    },
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getPlatformData();
    },

    getCompanyData() {
      IOT.getServerData("/company/listNew", "get", this.searchData, (ret) => {
        if (ret.code === 200) {
          this.companies = ret.rows;
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },

    clearSearchData() {
      this.searchData.keyWords = "";
    },

    pass(id) {
      this.$confirm("确认审核通过?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //审核通过
          IOT.getServerData(
            "/company/verify",
            "get",
            { companyId: id, result: 1},
            (ret) => {
              if (ret.code === 200) {
                getCompanyData();
                this.$message({
                  type: "success",
                  message: "审核通过成功!",
                });
              } else {
                IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
              }
            }
          );
        })
        .catch(() => {});
    },

    refuse(id) {
      this.$confirm("确认审核为不通过?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //审核不通过
          IOT.getServerData(
            "/company/verify",
            "get",
            { companyId: id, result: 2},
            (ret) => {
              if (ret.code === 200) {
                this.$message({
                  type: "success",
                  message: "审核通过成功!",
                });
                getCompanyData();
              } else {
                IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
              }
            }
          );
          this.$message({
            type: "success",
            message: "审核不通过成功!",
          });
        })
        .catch(() => {});
    },
  },
};
</script>